package com.zhouzhou.fastjava.excel;

import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.List;

public class ColumnQualifier {

    public static final ColumnQualifier IGNORE = null;

    public static final List<String> BOOLEANS = Lists.newArrayList("yes", "no", "y", "n", "on", "off", "t", "f", "no",
            "true", "false", "YES", "NO", "Y", "N", "ON", "OFF", "T", "F", "NO", "TRUE", "FALSE");

    private boolean allowBlank = true;

    private boolean unique = false;

    private boolean mustNumber;

    // 整数位最长长度
    private int precision;

    // 小数位最长长度
    private int scale;

    private final String name;

    private Float min;

    private Float max;

    private List<String> ins;

    private Call call;

    private int maxLength = Integer.MAX_VALUE;

    public ColumnQualifier(String name) {
        this.name = name;
    }

    private boolean mustPositiveNumber;

    public boolean isAllowBlank() {
        return allowBlank;
    }

    public ColumnQualifier setAllowBlank(boolean allowBlank) {
        this.allowBlank = allowBlank;
        return this;
    }

    public ColumnQualifier setUnique(boolean unique) {
        this.unique = unique;
        return this;
    }

    public boolean isUnique() {
        return unique;
    }

    public boolean isMustNumber() {
        return mustNumber;
    }

    public ColumnQualifier setMustNumber(boolean mustNumber) {
        this.mustNumber = mustNumber;
        return this;
    }

    public String getName() {
        return name;
    }

    public Float getMin() {
        return min;
    }

    public ColumnQualifier setMin(Float min) {
        this.min = min;
        return this;
    }

    public Float getMax() {
        return max;
    }

    public ColumnQualifier setMax(Float max) {
        this.max = max;
        return this;
    }

    public List<String> getIns() {
        return ins;
    }

    public ColumnQualifier setIns(String... ins) {
        this.ins = Arrays.asList(ins);
        return this;
    }

    public ColumnQualifier setIns(List<String> ins) {
        this.ins = ins;
        return this;
    }

    public ColumnQualifier setBool(boolean bool) {
        if (bool) {
            setIns(BOOLEANS);
        }
        return this;
    }

    public Call getCall() {
        return call;
    }

    public ColumnQualifier setCall(Call call) {
        this.call = call;
        return this;
    }

    public int getPrecision() {
        return precision;
    }

    public ColumnQualifier setPrecision(int precision) {
        this.precision = precision;
        return this;
    }

    public int getScale() {
        return scale;
    }

    public ColumnQualifier setScale(int scale) {
        this.scale = scale;
        return this;
    }

    public ColumnQualifier setMustPositiveNumber(boolean mustPositiveNumber) {
        this.mustPositiveNumber = mustPositiveNumber;
        if (mustPositiveNumber) {
            mustNumber = mustPositiveNumber;
        }
        return this;
    }

    public boolean isMustPositiveNumber() {
        return mustPositiveNumber;
    }

    public int getMaxLength() {
        return maxLength;
    }

    public ColumnQualifier setMaxLength(int maxLength) {
        this.maxLength = maxLength;
        return this;
    }

}
